<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE HTML>
<html>
<head>
    <title>俊英美发</title>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <script type="text/javascript" src="/js/jquery-3.2.1.min.js"></script>
    <script type="text/javascript" src="/js/bootstrap/bootstrap.min.js"></script>
    <script type="text/javascript" src="/js/bootstrap/html5shiv.min.js"></script>
    <script type="text/javascript" src="/js/respond.min.js"></script>
    <script type="text/javascript" src="/js/pace/pace.min.js"></script>
    <script type="text/javascript" src="/js/jquery.hammer/hammer.min.js"></script>
    <script src="/js/jquery.scrolltopcontrol/scrolltopcontrol.js" type="text/javascript"></script>
    <script src="/js/jquery.extend.js" type="text/javascript"></script>
    <script src="/js/dialog.js"></script>
    <script src="/js/comm.js" type="text/javascript"></script>

    <link href="/css/bootstrap/bootstrap.css" rel="stylesheet" />
    <link href="/css/font-awesome.css" rel="stylesheet" />
    <link href="/css/pace/dataurl.css" rel="stylesheet" />
    <link href="/css/dialog.css" rel="stylesheet" />

    <link href="/css/common.css" rel="stylesheet" />

    <style type="text/css">
        a:hover{
            cursor: pointer;
        }
    </style>
    <script>
        $(function () {

            pageInitModule.setWidth();
            //pageInitModule.setSidebar();
            //pageInitModule.setCarousel();

            $.ajaxSetup( {
                //设置ajax请求结束后的执行动作
                complete :
                    function(XMLHttpRequest, textStatus) {
                        // 通过XMLHttpRequest取得响应头，sessionstatus
                        var sessionstatus = XMLHttpRequest.getResponseHeader("sessionstatus");
                        if (sessionstatus == "TIMEOUT") {
                            var win = parent.window;
                            while (win != win.top){
                                win = win.top;
                            }
                            win.location.href= XMLHttpRequest.getResponseHeader("CONTEXTPATH");
                        }
                    }
            });
        })
        $(window).resize(function () {
            pageInitModule.setWidth();
        })
        $(window).scroll(function () {
            pageInitModule.setScrollToTop();
        });

        /*
         * init page when page load
         */
        var pageInitModule = (function (mod) {
            mod.setWidth = function () {
                if ($(window).width() < 768) {
                    $(".sidebar").css({ left: -220 });
                    $(".all").css({ marginLeft: 0 });
                } else {
                    $(".sidebar").css({ left: 0 });
                    $(".all").css({ marginLeft: 220 });
                }
            };
            mod.setScrollToTop = function () {
                var top = $(window).scrollTop();
                if (top < 60) {
                    $('#goTop').hide();
                } else {
                    $('#goTop').show();
                }
            };
            mod.setSidebar = function () {
                $('[data-target="sidebar"]').click(function () {
                    var asideleft = $(".sidebar").offset().left;
                    if (asideleft == 0) {
                        $(".sidebar").animate({ left: -220 });
                        $(".all").animate({ marginLeft: 0 });
                    }
                    else {
                        $(".sidebar").animate({ left: 0 });
                        $(".all").animate({ marginLeft: 220 });
                    }
                });
                $(".has-sub>a").click(function () {
                    $(this).parent().siblings().find(".sub-menu").slideUp();
                    $(this).parent().find(".sub-menu").slideToggle();
                })
            }
            return mod;
        })(window.pageInitModule || {});

        var firstId = "";
        $(function () {
            getHeight();

            $('[data-target="sidebar"]').click(function () {
                var asideleft = $(".sidebar").offset().left;
                if (asideleft == 0) {
                    $(".sidebar").animate({ left: -220 });
                    $(".all").animate({ marginLeft: 0 });
                }
                else {
                    $(".sidebar").animate({ left: 0 });
                    $(".all").animate({ marginLeft: 220 });
                }
            });

            $(".has-sub>a").click(function () {
                $(this).parent().siblings().find(".sub-menu").slideUp();
                $(this).parent().find(".sub-menu").slideToggle();
            })


            getResource();
        })

        //获取资源
        function getResource(){
            $.post("/main/getMainResource.do",function(data){
               var title_bar = eval("("+data+")");
               $("#main-bar").empty();
               firstId = title_bar[0].id;
               for(var i=0;i<title_bar.length;i++){
                   var data = title_bar[i];

                   var html = "<li><a  onclick='leftResource("+data.id+")'>"+data.name+"</a></li>";
                   $("#main-bar").append(html);
               }

               //获取左边信息
                leftResource(firstId);
            });
        }

        function leftResource(id){
            $.post("/main/getResource.do",{"parentId":id},function(data){
                $("#left-bar").empty();
                var showHtml = data[0];
                var showChildren = showHtml.isChildren;
                if(showChildren!=true){
                    $("#mainIframe").attr("src", showHtml.url+"?btnPurid="+showHtml.id);
                }

                for(var i=0;i<data.length;i++){
                    var info = data[i];
                    var isChildren = info.isChildren;
                    var html = "";

                    if(isChildren==true){
                        html =  "<li class='has-sub' id="+info.id+">";
                        html += "<a href='javascript:void(0);' onclick='choseChldrenId("+info.id+")'><span>"+info.name+"</span><i class='fa fa-caret-right fa-fw pull-right'></i></a>"
                        html += "<ul class='sub-menu' id='"+info.id+"ul'>";
                        html += "</ul>";
                        html += "</li>";
                    }else {
                        var urls = info.url;
                        if(urls!="node"){
                            html = "<li onclick='changeIframe(\""+urls+"?btnPurid="+info.id+"\")'><a href='javascript:void(0);' >"+info.name+"</a></li>";

                        }
                    }
                    $("#left-bar").append(html);
                }


            },"json");
        }

        function choseChldrenId(infoId){
            $.post("/main/getResource.do",{"parentId":infoId},function (data) {
                console.info(data);
                $("#"+infoId+"ul").empty();
                for(var i=0;i<data.length;i++){
                    var info = data[i];
                    $("#"+infoId+"ul").append("<li onclick='changeIframe(\""+info.url+"\")'><a href='javascript:void(0)' id="+info.id+" ><i class='fa fa-circle-o fa-fw'></i>&nbsp;&nbsp;"+info.name+"</a></li>");
                    }

                $("#"+infoId).siblings().find(".sub-menu").slideUp();
                $("#"+infoId).find(".sub-menu").slideToggle();
            },"json");

        }
        
        function changeIframe(url) {
            $('#mainIframe').attr('src', url);
        }

        function getHeight() {
            var winHeight = 0;
            if (window.innerHeight) {
                winHeight = window.innerHeight;
            } else if ((document.body) && (document.body.clientHeight)) {
                winHeight = document.body.clientHeight;
            }
            winHeight = winHeight - 52;
            $("#mainIframe").css({ "height": winHeight });
        }

        //修改密码
        function editPasswd() {
            var elem = document.getElementById('addEditForm');
            dialog({
                title: "修改密码",
                content: elem,
                width: '300px',
                okValue: "确定",
                ok : function () {
                    if(!checkInput()){
                        return false;
                    }
                    var data = {};
                    data["passwdNew"] = $("#passwdNew").val();
                    data["passwdOld"] = $("#passwdOld").val();
                    var b = false;
                    $.ajax({
                        url: "/main/editPasswd.do",
                        data: data,
                        dataType:"json",
                        type:"POST",
                        async: false,
                        success:function (datas) {
                            b = datas.value;
                        }
                    })
                    if(b){
                        okDail("修改成功！");
                    }else {
                        errorDail("修改失败！");
                    }
                },
                cancelValue: '取消',
                cancel: function () {}
            }).showModal();
        }
        
        function checkInput() {
            var b = true;
            b = checkValue("passwdOld");
            b = checkValue("passwdNew");
            return b;
        }
    </script>
</head>
<body style="overflow-y: hidden">
<nav class="navbar navbar-inverse navbar-fixed-top">
    <div class="container-fluid">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle show pull-left" data-target="sidebar">
                <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span>
            </button>
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar"
                    aria-expanded="false" aria-controls="navbar">
                <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="javascript:void(0)">主页</a>
        </div>
        <div id="navbar" class="collapse navbar-collapse">
            <ul class="nav navbar-nav" id="main-bar">
            </ul>
            <ul class="nav navbar-nav navbar-right">
                <li class="dropdown">
                    <a href="javascript:void(0);" class="dropdown-toggle" data-toggle="dropdown" role="button"
                       aria-expanded="false"><i class="fa fa-user fa-fw"></i>&nbsp;${user}&nbsp;<span class="caret"></span></a>
                    <ul class="dropdown-menu" role="menu">
                        <li><a href="/register.do" >安全退出</a></li>
                        <li><a href="javascript:void(0);" onclick="editPasswd();">修改密码</a></li>
                    </ul>
                </li>
            </ul>
        </div>
    </div>
</nav>
<div class="container-fluid all">
    <div class="sidebar">
        <ul class="nav" id="left-bar">

        </ul>
    </div>
    <div class="maincontent row">
        <!--我是主要内容 end-->
        <iframe id="mainIframe" style="width: 100%;height:100%;border: 0px;margin: 0px auto;padding: 0px auto;overflow-x: hidden;" >

        </iframe>
    </div>
</div>
<a href="#top" id="goTop"><i class="fa fa-angle-up fa-3x"></i></a>
<div id="addEditForm" style="display: none;">
    <div style="width: 100%;margin-top: 10px;">
        <form class="form-horizontal" id="nodeForm" role="form">
            <div class="form-group">
                <label class="col-sm-4 control-label">原始密码<span style="color: red;">*</span></label>
                <div class="col-sm-7">
                    <input type="text" class="form-control" id="passwdOld" name="passwdOld" placeholder="原始密码" onBlur="onBlurValue(this)">
                    <span class="help-block" style="color: red; display: none;">请输入原始密码</span>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-4 control-label">新密码<span style="color: red;">*</span></label>
                <div class="col-sm-7">
                    <input type="text" class="form-control"  id="passwdNew" name="passwdNew"  placeholder="新密码" onBlur="onBlurValue(this)">
                    <span class="help-block" style="color: red; display: none;">请输入新密码</span>
                </div>
            </div>

        </form>
    </div>
</div>
</body>
</html>
